package function.listen;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;

import javax.swing.JPanel;

import frame.master;
import frame.data.contrldata;

public class fileinfolisten {
	public fileinfolisten() {
		contrldata.fileinfo=new JPanel() {
			@Override
			protected void paintComponent(Graphics g) {
				drawfileinfo(g,getWidth(),getHeight());
			}
		};
		contrldata.fileinfo.setPreferredSize(new Dimension(master.WIDTH, 20));
	}
	/**
	 * 绘制文件信息
	 * @param g
	 * @param width
	 * @param height
	 */
	private void drawfileinfo(Graphics g,int width,int height) {
		try {
			g.setColor(new Color(240,240,240));
			g.fillRect(0, 0, width, height);
			g.setColor(new Color(120,120,120));
			FontMetrics fm=g.getFontMetrics();
			String allline="lines:"+contrldata.jt.getLineCount();
			g.drawString(allline, 5, 16);
			int line=contrldata.jt.getLineOfOffset(contrldata.jt.getCaretPosition())+1;
			String ln="Ln:"+line;
			g.drawString(ln, fm.stringWidth(allline)+25,16);
			String col="Col:"+(contrldata.jt.getCaretPosition()-contrldata.jt.getLineStartOffset(line-1));
			g.drawString(col, fm.stringWidth(allline+ln)+45,16);
			String sel="Sel/Lns:";
			if(contrldata.jt.getSelectedText()!=null)sel+=contrldata.jt.getSelectedText().replaceAll("\n", "").length()
					+"/"+(contrldata.jt.getLineOfOffset(contrldata.jt.getSelectionEnd())
							-contrldata.jt.getLineOfOffset(contrldata.jt.getSelectionStart())+1);
			else sel+="0/0";
			g.drawString(sel, fm.stringWidth(allline+ln+col)+65, 16);
			String co="Code:"+master.fl.getfileinfoofnum(master.editfilenum).getCode();
			g.drawString(co, fm.stringWidth(allline+ln+col+sel)+85, 16);
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}
